import 'package:fluttertoast/fluttertoast.dart';
import 'package:sui_shou_pai/Utils/storage_util.dart';
import 'package:sui_shou_pai/chat/entity/global.dart';
import 'package:sui_shou_pai/chat/init/init_map.dart';
import 'package:sui_shou_pai/network/http_config.dart';
import 'package:sui_shou_pai/network/http_request.dart';

class InitInformation {
  static String name = '';
  static String employeeId = '';
  static String avatar = '';
  static String phone = '';
  static String sex = '';
  static String birth = '';
  static String position = '';
  static String id = '';
  static String role = '';

  static initInform() {
    initData();
  }

  static Future<void> initData() async {
    print(await StorageUtil.getStringItem("employeeId"));
    HttpRequest.request("$BASE_URL/employee/getInform",
            method: "post",
            params: {
              "employeeId": await StorageUtil.getStringItem("employeeId")
            },
            token: await StorageUtil.getStringItem("token"))
        .then((value) async {
      if (value.data["code"] == 200) {
        name = value.data['result']['name'];
        employeeId = value.data['result']['employeeId'];
        avatar = value.data['result']['avatar'];
        phone = value.data['result']['phone'];
        sex = value.data['result']['gender'];
        birth = value.data['result']['birth'];
        birth = birth.substring(0, 10);
        position = value.data['result']['position'];
        id = value.data['result']['id'].toString();
        role = await StorageUtil.getStringItem("role");
        Global.setMyId(id);
        InitMap.initGlobalMap();
      } else {
        Fluttertoast.showToast(msg: "加载失败");
      }
    });
  }
}
